#!/usr/bin/env jq
# compile-config-2.03-calibration_plots -- Adds processes for producing calibration plots
##

# skip adding process for calibration plots unless one for inference is there
if .deepdive_.execution.processes | has("process/model/inference") | not then . else

.deepdive_ as $deepdive
| .deepdive_.execution.processes += {

    # calibration plots
    "process/model/calibration": {
        dependencies_: ["data/model/probabilities", "process/model/load_probabilities"],
        output_: ["model/calibration-plots"],
        style: "cmd_extractor",
        cmd: "
            d=../../../model/calibration-plots && mkdir -p \"$d\" && cd \"$d\"
            # XXX a legacy location under the current run directory for backward compatibility
            extraOutput=\"${DEEPDIVE_OUTPUT:-../../RUNNING}\"/calibration && mkdir -p \"$extraOutput\"
            DEEPDIVE_CALIBRATION_NUM_BUCKETS=10
            \([ $deepdive.schema.variables_[] | "
            # create a view and draw a calibration plot for variable \(.name)
            deepdive db create_calibration_view \(.variableName | @sh)
            draw_calibration_plot      \(.variableName | @sh)
            # XXX keeping a duplicate copy under the current run directory for backward compatibility
            cp -a \(.variableName | @sh).* \"$extraOutput\"/
            "] | join("\n"))
        "
    }

}

end
